package com.yaowk.system.server.service.impl;

import com.yaowk.system.api.model.Resource;
import com.yaowk.system.server.dao.MenuDao;
import com.yaowk.system.server.service.base.ResourceServiceBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@CacheConfig(cacheNames = "resource")
public class ResourceServiceImpl extends ResourceServiceBase {

    @Autowired
    private MenuDao menuDao;

    @Override
    @Cacheable
    public List<Resource> findAll() {
        return super.findAll();
    }

    @Override
    @CacheEvict(allEntries = true)
    public Resource save(Resource model) {
        return super.save(model);
    }

    @Override
    @CacheEvict(allEntries = true)
    public void deleteById(Long aLong) {
        super.deleteById(aLong);
    }

    @Override
    public List<Resource> findAllByMenuId(Long menuId) {
        return entity2Model(menuDao.findOne(menuId).getResources());
    }
}